package com.tengfei.adapterdemo;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.tengfei.adapterdemo.adapter.FrameworkAdapter;
import com.tengfei.adapterdemo.adapter.MyListViewAdapter;
import com.tengfei.adapterdemo.entry.ReceiveData;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ImageFrameworkActivity extends AppCompatActivity {

    private final String URL = "https://imgapi.cn/api.php?fl=meizi";

    private final int IMG_COUNT = 20;

    private ListView mLv;

    private MyListViewAdapter myListViewAdapter;

    private List<ReceiveData.PhotoData> datas = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_framework);
        // 设置状态栏标题
        getSupportActionBar().setTitle("自定义adapter下框架加载图片");
        mLv = findViewById(R.id.my_lv_2);
        initAdapter();
    }

    private void initAdapter() {
        // 获取屏幕的宽度
        DisplayMetrics outMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
        int screenWidth = outMetrics.widthPixels;
        // 添加到容器中
        Map<String, Object> maps = new HashMap<>();
        maps.put("img_count", IMG_COUNT);
        maps.put("url", URL);
        maps.put("screenWidth", screenWidth);
        // 加载到adapter中
        FrameworkAdapter frameworkAdapter = new FrameworkAdapter();
        frameworkAdapter.setMap(maps);
        mLv.setAdapter(frameworkAdapter);
    }
}